﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Axe
{
    public static partial class Utility
    {
        #region public static char[] CreateCharactersSequence(char starChar, char endChar)
        public static char[] CreateCharactersSequence(char starChar, char endChar)
        {
            char[] chars = new char[endChar - starChar + 1];

            int i = 0;
            for (char c = starChar; c <= endChar; c++)
            {
                chars[i++] = c;
            }

            return chars;
        } 
        #endregion

        #region public static string GenerateRandomString(int length)
        public static string GenerateRandomString(int length)
        {
            if (length < 0)
                throw new ArgumentOutOfRangeException("String length cannot be less than zero.");
            if (length == 0)
                return String.Empty;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                sb.Append(m_Random.Next());
            }

            return MD5(sb.ToString());
        } 
        #endregion

        #region public static string ToString(byte[] array)
        public static string ToString(byte[] array)
        {
            StringBuilder sb = new StringBuilder();

            int arrayLen = array.Length;

            for (int i = 0; i < arrayLen; i++)
            {
                sb.AppendFormat("{0:x}", array[0]);

                if (i < arrayLen)
                    sb.Append(" ");
            }

            return sb.ToString();
        } 
        #endregion

        #region public static string Intern(string str)
        public static string Intern(string str)
        {
            if (str == null)
                return null;
            else if (str.Length == 0)
                return String.Empty;

            return String.Intern(str);
        } 
        #endregion
    }
}
